// 求一个数的整数次方
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

// 最简单但同时也是最差的解法
double PowerOne(double num, double pow)
{
	int i = 0;
	int result = 1;
	for(i = 0; i < pow; ++i) {
		result *= num;
	}
	return result;
}

double PowerTwo(double num, double pow)
{
	if(0.0 == num) {
		printf("Zero has no means\n");
		return 0;
	}

	unsigned int temp = (unsigned int)(pow);
	printf("Debug : %d\n", temp);

	if(pow < 0) {
		temp = (unsigned int)(-pow);
		printf("Debug : %d\n", temp);
	}

	int result = PowerOne(num, temp);
	if(pow < 0) {
		return 1.0/result;
	}
	return result;
}

int main()
{
	double num = 0;
	double pow = 0;
	printf("Please Input : ");
	scanf("%lf, %lf", &num, &pow);

	printf("%2.1lf的%2.1lf次方是 : %2.3lf\n", num, pow, PowerOne(num, pow));
	printf("%2.1lf的%2.1lf次方是 : %2.3lf\n", num, pow, PowerTwo(num, pow));

	return 0;
}
